package com.example.myapplication.options;

import android.graphics.Bitmap;

import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.annotation.GlideExtension;
import com.bumptech.glide.annotation.GlideOption;
import com.bumptech.glide.annotation.GlideType;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.BaseRequestOptions;
import com.example.myapplication.R;

import jp.wasabeef.glide.transformations.BlurTransformation;

@GlideExtension
public class MyGlideExtension {


    private MyGlideExtension(){}

    @GlideOption
    public static BaseRequestOptions<?> applyAvatar(BaseRequestOptions<?> options,int size){

        //  所有通用的设置都在这里设置
        BlurTransformation transformation = new BlurTransformation(25,1);//  图片模糊处理
        return options.placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher)
                .override(size)
//                .fitCenter()
//                .transform(transformation);
//                .circleCrop();// 图片圆形处理
                .transform(new MultiTransformation<>(transformation,new CircleCrop()));
    }

    //  自定义返回类型
    @GlideType(Bitmap.class)
    public static RequestBuilder<Bitmap> fade(RequestBuilder<Bitmap> requestBuilder) {
        return requestBuilder.transition(BitmapTransitionOptions.withCrossFade());
    }
}
